package com.example.element.module.jetpack.livedata

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class LiveDataViewModel(countReserved: Int) : ViewModel() {

    //    val counter=MutableLiveData<Int>()
    private val _counter = MutableLiveData<Int>()
    val counter: LiveData<Int> get() = _counter


    init {
        _counter.value = countReserved
    }

    fun plusOne() {
        val count = counter.value ?: 0
        _counter.value = count + 1
    }

    fun clear() {
        _counter.value = 0
    }


}